﻿/* Return isAdd:
* 1    :success
* 2    : Article Group is null or empty
* 3    : Article Group is not valid
* 10   : Article title is null or empty
* 11   : Article Title is less than 6 characters
* 12   : Article Title is greater than 100
*/
function AddArticleValid(groupId, title) {

    var rGroupId = new RegExp("[0-9a-zA-Z]");
    if (!rGroupId.exec(groupId)) {
        return 2;
    }

    rGroupId = new RegExp("^[0-9]{0,}$");
    if (!rGroupId.exec(groupId)) {
        return 3;
    }

    var rTitle = new RegExp("[0-9a-zA-Z]");
    if (!rTitle.exec(title)) {
        return 10;
    }
    else if (title.length < 6) {
        return 11;
    }
    else if (title.length > 100) {
        return 12;
    }

    return 1;
}

/* Return:
* 1    :success
* 2    : Article is null or empty
* 3    : Article is not valid
* 4    : Article Group is null or empty
* 5    : Article Group is not valid
* 10   : Article title is null or empty
* 11   : Article Title is less than 6 characters
* 12   : Article Title is greater than 100
*/
function EditArticleValid(articleId, groupId, title)
{
    var rArticleId = new RegExp("[0-9a-zA-Z]");
    if (!rArticleId.exec(articleId)) {
        return 2;
    }

    rArtileId = new RegExp("^[0-9]{0,}$");
    if(!rArtileId.exec(articleId)) {
        return 5;
    }

    var rGroupId = new RegExp("[0-9a-zA-Z]");
    if (!rGroupId.exec(groupId)) {
        return 3;
    }

    rGroupId = new RegExp("^[0-9]{0,}$");
    if (!rGroupId.exec(groupId)) {
        return 4;
    }
    
    var rTitle = new RegExp("[0-9a-zA-Z]");
    if (!rTitle.exec(title)) {
        return 10;
    }
    else if (title.length < 6) {
        return 11;
    }
    else if (title.length > 100) {
        return 12;
    }

        return 1;
}